package cn.com.bluemoon.daps.system;

import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.enums.DatabaseType;
import cn.com.bluemoon.daps.common.toolkit.AesEncryptUtils;
import cn.com.bluemoon.daps.system.entity.DapSystemDatasourceEnvironment;
import cn.com.bluemoon.daps.system.utils.ConnectUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnect {

    @Test
    public void test(){

        DapSystemDatasourceEnvironment pgsql = new DapSystemDatasourceEnvironment();
        pgsql.setDatabaseSchema("public");
        pgsql.setDatabaseName("postgres");
        pgsql.setUsername("readonly_gov");
        pgsql.setPassword("qslu#&87");
        pgsql.setHost("192.168.235.3");
        pgsql.setPort(5432);
        DapSystemDatasourceEnvironment mysql = new DapSystemDatasourceEnvironment();
        mysql.setDatabaseName("data_asset_platform");
        mysql.setUsername("dsmanager");
        mysql.setPassword("ufxErKTi");
        mysql.setHost("192.168.234.4");
        mysql.setPort(3307);
        DapSystemDatasourceEnvironment hive = new DapSystemDatasourceEnvironment();
        hive.setDatabaseName("default");
        hive.setUsername("hive");
        hive.setHost("192.168.39.3");
        hive.setPort(10000);
        hive.setPassword("");
        String result = ConnectUtils.connectTest(DatabaseType.HIVE, hive);
        System.out.println(result);

    }

    @Test
    public void hiveConnect() throws Exception {
        //连接hive中数据库的驱动、URL、用户名、密码
        String driver = "org.apache.hive.jdbc.HiveDriver";
        String url = "jdbc:hive2://192.168.39.3:10000/default";
        String username = "hive";
        String password = "";
        //加载驱动，连接数据库
        try {
            Class.forName(driver);
            Connection connection = DriverManager.getConnection(url, username, password);
            connection.close();
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void password() throws Exception {

        String encrypt = AesEncryptUtils.decrypt("/GjGUE+vpZh4/fVMdJktdA==");
        System.out.println(encrypt);

    }
}
